<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>
      <ul>
        <li :class="{ active: activeFlag === '' }" @click="chengActive('')">
          全部
        </li>
        <li
          v-for="item in regionArr"
          :key="item.id"
          :class="{ active: activeFlag === item.value }"
          @click="chengActive(item.value)"
        >
          {{ item.name }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { reqHospitalLevelAndRegion } from "@/api/home/index";
import { HospitalLevelAndRegionArr, HospitalLevelAndRegionResponseData } from "@/api/home/type";

let regionArr = ref<HospitalLevelAndRegionArr>([]);
let activeFlag = ref<string>("");
onMounted(() => {
  getLevel();
});
const getLevel = async () => {
  let res: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion("Beijin");
  if (res.code === 200) {
    regionArr.value = res.data;
  }
};
const chengActive = (leve: string) => {
  activeFlag.value = leve;
  $emit('getRegion',leve)
};
let $emit =  defineEmits(['getRegion'])
</script>

<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 20px;
  .content {
    display: flex;
    .left {
      margin-right: 10px;
      width: 50px;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 10px;
        margin-bottom: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>
